package com.aqiang.core.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.aqiang.core.presenter.BasePresenter;

public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity implements IView {
    protected P mPresenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        createPresenter();
        setContentView(bindLayout());
        initView(savedInstanceState);
        initData();
        initEvent();
    }

    protected abstract void initEvent();

    protected abstract void createPresenter();

    protected abstract void initData();

    protected abstract void initView(Bundle savedInstanceState);

    protected abstract int bindLayout();

    protected void showToast(String msg){
        Toast.makeText(this, ""+msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter != null){
            mPresenter = null;
        }
    }
}
